<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';
include("FCKeditor/fckeditor.php") ;
$status = $_SESSION['status'];
if('Premium' == $status) {
	$jobcontact = array("1" => 'Candidates', '2' => 'Recruiters');
} else {
	$jobcontact     = array('2' => 'Network');
	$jobcontact_tip = array('2'=>'Check here if you wish to also post this job to the network for view by other Recruiter members.');
}
//print_r($_SESSION);
$smarty->compile_check = true;
include("./check/checkpostjob.php");

$jobid = ($_GET[id])?$_GET[id]:$_POST[id];
$jobid = $jobid+0;


$smarty->display('header.tpl');

$rs  = $DB->fetch_one_array("SELECT * FROM pa_job WHERE `jo_uid`=".$_SESSION[uid]." AND `jo_id` =".$jobid );

$_GET[view]=="op"&& $rs  = $DB->fetch_one_array("SELECT * FROM pa_job WHERE `jo_id` =".$jobid );

$rsp = $DB->fetch_one_array("SELECT * FROM pa_job WHERE `jo_utype`='".$_SESSION[usertype]."' AND `jo_id` ='".$jobid."' AND `jo_uid`='".$_SESSION[uid]."'");

if($rs[jo_id]!=''){$jobid = $rs[jo_id];}
if(empty($rsp)){
    $otherjob = 1;
}

if(empty($rs)||$jobid==''){
	   $err = "Invalid ID!";
	   $smarty->assign("err",$err);
	   $smarty->display("left.tpl");
	   $smarty->display("error.tpl");
	   $smarty->display("right.tpl");
	   $smarty->display('footer.tpl');
	   exit;
}
if($_GET[action]=="delete"){
       $sql = "DELETE FROM pa_job WHERE `jo_id`=".$jobid;
       $DB->query($sql);
	   redirect2("myjobs.php");
	   exit;
}else{
	  
	    
		ob_clean();
		ob_start();

		if($_GET[action]=="view"){
		$title   = "<h2>View Job</h2>";
		$cpforms->formheader(array('title'=>'Job Record','name'=>'article'));
		$view = 1;
		}else{
		$cpforms->formheader(array('title'=>'Job Record','name'=>'article','extra'=>'name="postjob"'));
		$title   = "Post/Edit Job(<font color=red>*</font>=Required Field)";
		}

		$smarty->assign("preview",'<input  type="submit" name="preview" class="button-secondary" value=" Preview " onclick=\'document.postjob.target="";document.postjob.action="previewjob.php"; $("#article").submit();\' />');

		//$cpforms->formheader(array('title'=>'Job Record','name'=>'article'));
		$cpforms->makehidden(array('name'=>'id','value'=>$jobid));
		$cpforms->makehidden(array('name'=>'offset','value'=>$offset));
		$cpforms->makehidden(array('name'=>'action','value'=>'upd_job'));
		$cpforms->gethightext(array('text'=>"Create Date",'value'=>date("m/d/Y",$rs[jo_regtime]),'view'=>"1"));
		if($rs[jo_updtime]==0){$rs[jo_updtime] = $rs[jo_regtime];}
		$cpforms->gethightext(array('text'=>"Last Updated",'value'=>date("m/d/Y",$rs[jo_updtime]),'view'=>"1"));
		$cpforms->gethightext(array('text'=>"ER Job Req#",'value'=>$rs[jo_id],'view'=>"1"));
		
		$cpforms->longline(array('title'=>"Post Options"));

		$rs['jo_contact'] = explode(",", $rs["jo_contact"]);
		if($_SESSION[usertype]=='employer'){
		$cpforms->getBoxes(array('one'=>1,'text'=>"Post To",'name'=>"jo_contact[]",'view'=>"$view",'selected'=>$rs[jo_contact],'option'=>$jobcontact_for_employer, 'notice_option'=>$jobcontact_tip_for_employer, 'text_tip'=>'Please select who may contact you regarding this job.'));
		}else{
		$standardContacts = array_unique(array_merge($rs[jo_contact],array(4)));
		$rs[jo_contact] = ('Premium' == $status)?$standardContacts:$standardContacts;
		$disableArr = ('Premium' == $status)?array(4):array(4);

		$cpforms->getBoxes(array('one'=>1,'text'=>"Post To",'name'=>"jo_contact[]",'view'=>"$view",'selected'=>$rs[jo_contact],'option'=>$jobcontact, 'notice_option'=>$jobcontact_tip,'disableArr'=>$disableArr));
		}

		if('Standard' == $status){ $jobCatOption = array('-- SELECT ALL --','2'=>'Job Split'); if(!$rs[jo_cat]){$rs[jo_cat]=2;}}
		if($rs[jo_cat] == 2) $smarty->assign('splitfee',1);
		$cpforms->makeselect(array('one'=>1,'only'=>1,'text'=>"Job Category",'name'=>"jo_cat",'selected'=>"$rs[jo_cat]",'view'=>"$view",'option'=> $jobCatOption,  'selectextra'=>' id="jo_cat" onchange="changeOptions(\'jobsplit\')"'));

		echo '<tr nowrap="" class="firstalt" id="jobsplit">
				<td width="40%">
					 Fees and Terms:
				</td>
				<td width="60%">
				   <textarea rows="3" cols="50" name="jo_bonus" id="jo_bonus" type="text"></textarea><br/>
				   <input type="button" value=" Add " id="jo_bonus_btn" class="button-secondary"><br/>
				   <div id="jo_bonus_show" style="border:1px solid #ccc;height:120px;overflow-y:auto;">'.nl2br($rs[jo_bonus]).'</div>
				 </td>
				</tr>';

		echo '<script>
			function ajaxpost(){
				var jo_bonus_text = $("#jo_bonus").val();
				$.ajax({
					type	: "POST",
					cache	: false,
					url	    : "sentsuccess.php",
					dataType: "json",
					data	: {id:"'.$jobid.'",jo_bonus:jo_bonus_text,action:"jobedit_ajax"},
					success: function(data) {
						if(data.status = 1)
						{
							$("#jo_bonus_show").html(data.text);
							$("#jo_bonus").val("");
						}
					}
				});
				return false;
			}

			$(document).ready(function() {
				$("#jo_bonus_btn").click(function(){
					$("#jo_bonus_btn").hide();
					ajaxpost();
					$("#jo_bonus_btn").show();
				});
			});
	</script>';


		$cpforms->longline(array('title'=>"Company Information",'icon'=>"'Your company information here.', WIDTH, 200, SHADOW, true"));

		$cpforms->gethightext(array('text'=>"Company Name",'name'=>"jo_copname",'only'=>1,'value'=>"$rs[jo_copname]",'view'=>"$view",'icon'=>"'If you are independent and don\'t have a company name simply enter your name here.', WIDTH, 200, SHADOW, true"));
		$cpforms->gethightext(array('text'=>"Company URL",'name'=>"jo_copurl",'value'=>"$rs[jo_copurl]",'view'=>"$view",'icon'=>"' Leave blank if you don\'t have a website.', WIDTH, 200, SHADOW, true"));
		$cpforms->gethightext(array('text'=>"Contact Name",'name'=>"jo_priname",'value'=>"$rs[jo_priname]",'view'=>"$view",'icon'=>"'Your name will not be shown on jobs posted.', WIDTH, 200, SHADOW, true"));
		$cpforms->gethightext(array('text'=>"Contact Email",'name'=>"jo_priemail",'value'=>"$rs[jo_priemail]",'view'=>"$view",'icon'=>"'Your email will not be shown on jobs posted. This email will receive all applicants and messages for this job.', WIDTH, 200, SHADOW, true"));
		$cpforms->gethightext(array('text'=>"Contact Phone",'name'=>"jo_priphone",'value'=>"$rs[jo_priphone]",'view'=>"$view",'icon'=>"'This information is private and only viewable by you.', WIDTH, 200, SHADOW, true"));

		$cpforms->longline(array('title'=>"Hiring Company Information (or your Client)",'icon'=>"'Your client or hiring company information here.', WIDTH, 200, SHADOW, true"));

		$cpforms->maketextarea(array('text'=>"About the Hiring Company",'name'=>"jo_copculture",'value'=>"$rs[jo_copculture]",'view'=>"$view",'icon'=>"'You can include the name of the hiring company, a description about the company or leave it blank.  You may edit this later.', WIDTH, 200, SHADOW, true"));
		$rs[jo_copbenefit] = $rs[jo_copbenefit]?$rs[jo_copbenefit]:"Not Disclosed.  Please contact Job Poster for details.";
		$cpforms->maketextarea(array('text'=>"Hiring Company Manager and Benefits",'name'=>"jo_copbenefit",'value'=>"$rs[jo_copbenefit]",'view'=>"$view",'icon'=>"'You may describe the hiring manager and company employee benefits or leave it blank.  You may edit this later.', WIDTH, 200, SHADOW, true"));


		$cpforms->longline(array('title'=>"Job Information"));
		$cpforms->gethightext(array('text'=>"Job Title",'name'=>"jo_title",'only'=>1,'value'=>"$rs[jo_title]",'view'=>"$view"));
		$cpforms->gethightext(array('text'=>"Job Valid By Date",'name'=>"jo_vdate",'value'=>"$rs[jo_vdate]",'view'=>"$view",'icon'=>"' Please indicate by which date this job will be open.',WIDTH, 200, SHADOW, true"));
		$cpforms->makeselect(array('one'=>1,'text'=>"Job Fill Status",'only'=>1,'name'=>"jo_status",'view'=>"$view",'selected'=>"$rs[jo_status]",'option'=> $jobfillstatus,'icon'=>"' Please indicate OPEN or On-Hold if you wish to receive messages.  When you change the status to CLOSED, you will stop receiving messages and candidates.  You may edit this status anytime.',WIDTH, 200, SHADOW, true"));
		$cpforms->makeselect(array('one'=>1,'text'=>"Job Priority",'name'=>"jo_priority", 'selected'=>"$rs[jo_priority]",'view'=>"$view",'option'=> $priority,'icon'=>"' You can indicate the priority status of this job.  This is a private field and is only viewable by you.',WIDTH, 200, SHADOW, true"));
		
		$cpforms->makeselect(array('one'=>1,'text'=>"Job Type",'only'=>1,'name'=>"jo_type",'view'=>"$view",'selected'=>"$rs[jo_type]",'option'=>$jobtype));

		$cpforms->makeselect(array('one'=>1,'text'=>"Job Industry",'name'=>"jo_category",'only'=>1,'selected'=>"$rs[jo_category]",'view'=>"$view",'option'=> $jobcategory));
		$cpforms->makeselect(array('one'=>1,'text'=>"Job Function",'name'=>"jo_function",'only'=>1,'selected'=>"$rs[jo_function]",'view'=>"$view",'option'=> $jobfunction));
		$cpforms->gethightext(array('text'=>"Company Internal Req#",'name'=>"jo_copreq",'value'=>"$rs[jo_copreq]",'view'=>"$view",'icon'=>"' You can track your jobs by typing in an internal job req# or a client name.  This is a private field and only viewable by you.  You may edit this later. ', WIDTH, 200, SHADOW, true"));
		$cpforms->gethightext(array('text'=>"No. of Open Positions",'name'=>"jo_positions", 'value'=>"$rs[jo_positions]",'view'=>"$view"));
		$cpforms->gethightext(array('text'=>"Compensation(USD)",'name'=>"jo_salrange",'only'=>1,'value'=>"$rs[jo_salrange]",'view'=>"$view",'icon'=>"' Please indicate the pay range for this Job order.',WIDTH, 200, SHADOW, true"));
		

		//$cpforms->gethightext(array('text'=>"Placement Fee Estimate",'name'=>"jo_feerange",'value'=>"$rs[jo_feerange]",'view'=>"$view"));
		$cpforms->gethightext(array('text'=>"Work Address",'only'=>1,'name'=>"jo_address",'value'=>"$rs[jo_address]",'view'=>"$view"));
		$cpforms->gethightext(array('text'=>"Location - City",'name'=>"jo_city",'only'=>1,'value'=>"$rs[jo_city]",'view'=>"$view"));
		$cpforms->makeselect(array('one'=>1,'text'=>"Location - State/Region",'name'=>"jo_state",'only'=>1,'selected'=>"$rs[jo_state]",'view'=>"$view",'option'=> $state));
		$cpforms->makeselect(array('one'=>1,'text'=>"Location - Country",'name'=>"jo_country",'only'=>1,'selected'=>"$rs[jo_country]",'view'=>"$view",'option'=> $country));
		$cpforms->gethightext(array('text'=>"Location - Zip Code",'name'=>"jo_zip",'only'=>1,'value'=>"$rs[jo_zip]",'view'=>"$view"));
		$cpforms->makeselect(array('one'=>1,'text'=>"Will consider candidates how far from company location?",'name'=>"jo_howfar", 'selected'=>"$rs[jo_howfar]",'view'=>"$view",'option'=> $location));
		$cpforms->makeselect(array('one'=>1,'text'=>"Job Travel Requirement(%)", 'name'=>"jo_jobtravel",'selected'=>"$rs[jo_jobtravel]",'view'=>"$view",'option'=> $travel));
		//$cpforms->maketextarea(array('text'=>"About the Hiring Manager",'name'=>"jo_hiringmanager",'value'=>"$rs[jo_hiringmanager]",'view'=>"$view",'icon'=>"'Please describe the hiring manager for this position in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
		$cpforms->longline(array('title'=>"Job Qualifications"));

		$cpforms->gethightext(array('text'=>"Minimum Education Requirement",'name'=>"jo_mer", 'value'=>"$rs[jo_mer]",'view'=>"$view"));
		$cpforms->makeselect(array('one'=>1,'text'=>"Minimum Years of Relevant Work Experience",'name'=>"jo_myrwe", 'selected'=>"$rs[jo_myrwe]",'view'=>"$view",'option'=> $yearexp2));
		$cpforms->makeselect(array('one'=>1,'text'=>"Years of People Management Experience",'name'=>"jo_ypme", 'selected'=>"$rs[jo_ypme]",'view'=>"$view",'option'=> $yearexp2));
		$cpforms->makeselect(array('one'=>1,'text'=>"Years of Profit & Loss Responsibility",'name'=>"jo_yplr", 'selected'=>"$rs[jo_yplr]",'view'=>"$view",'option'=> $yearexp2));
		$cpforms->gethightext(array('text'=>"Industry License Requirement",'name'=>"jo_license",'value'=>"$rs[jo_license]",'view'=>"$view"));

		$cpforms->gethightext(array('text'=>"Required Language Skills",'name'=>"jo_language",'value'=>"$rs[jo_language]",'view'=>"$view"));
		$cpforms->gethightext(array('text'=>"Authorized to Work in Location",'name'=>"jo_authorized",'only'=>1,'value'=>"$rs[jo_authorized]",'view'=>"$view",'icon'=>"'Please indicate the Country or Region where job candidates must have the authorization or permit to work.', WIDTH, 200, SHADOW, true"));
		$cpforms->gethighradio(array('text'=>"U.S. Government Security Clearance",'name'=>"jo_usgsc",'selected'=>"$rs[jo_usgsc]",'view'=>"$view",'icon'=>"'Indicate whether or not this job requires U.S. government clearance.', WIDTH, 200, SHADOW, true"));
		$cpforms->makefck(array('text'=>"Job Description (Cut and Paste or Type-in)",'name'=>"jo_description",'id'=>"jo_description","only"=>1,'value'=>"$rs[jo_description]",'width'=>"570",'height'=>"400",'view'=>"$view",'icon'=>"'Please include all job details here in 3,000 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
		$cpforms->maketextarea(array('text'=>"Public Note",'name'=>"jo_public",'value'=>"$rs[jo_public]",'view'=>"$view",'icon'=>"'Public note is visible to others. Do not include contact information.', WIDTH, 200, SHADOW, true"));
		$cpforms->maketextarea(array('text'=>"Private Note",'name'=>"jo_private",'value'=>"$rs[jo_private]",'view'=>"$view",'icon'=>"'Private note is only visible to you.', WIDTH, 200, SHADOW, true"));
		//$cpforms->makePhpCaptcha(array('text'=>"Safe Code",'name'=>"imagecode",'value'=>"$_POST[imagecode]",'only'=>1));
		
		if($_GET[action]!="view"){
			echo '<tr class="tbhead">
				<td colspan="2" align="center" bgcolor="#F0F0F0">
				 <input class="bginput button-secondary" accesskey="" type="button" name="aaa" value=" Enter and Save "  onclick=\'document.postjob.target=""; document.postjob.action="postjob.php";  this.form.submit()\'  /> 
				  <input class="bginput button-secondary" type="button" name="preview" value=" Preview " onclick=\'document.postjob.target="";document.postjob.action="previewjob.php"; this.form.submit();\' />
				 <input class="bginput button-secondary" accesskey="" type="button" name="" value=" Cancel "  onclick="history.back(1)"  /> 
				<br></td></tr>
				</table></td></tr>
				</form>
				</table>';	
		}elseif($_GET[action]=='edit'){
		    $cpforms->formfooter();
		}

		if($_GET[action]=="view"){
			echo "<tr class=\"tbhead\"><td colspan=\"2\" align=\"center\" bgcolor=\"#F0F0F0\"><input class=\"bginput button-secondary\" type=\"button\" value=\"Back\" onclick=\"history.go(-1);\">&nbsp;&nbsp;&nbsp;<input class=\"bginput button-secondary\" type=\"button\" value=\"Submit Candidate\" onclick=\"location.href='submitapplicant.php?jid=".$jobid."'\"></td></tr></table></td></tr></table>\n";
		}

		$reg_data = ob_get_contents();
		ob_end_clean();

		$smarty->assign('title',$title);

		if($err!=''){
		$smarty->assign("err",$err);
		}
		$smarty->assign("reg",$reg_data);
		$smarty->display('allleft.tpl');
		$smarty->display('postjob.tpl');
		$smarty->display('allright.tpl');
		$smarty->display('footer.tpl');
}
?>
